package net.fkrahe.graph;

/**
 * Class WArcNode (Weightted ArcNode)
 * 
 * @author Yedidyah Langsan | Moshe Augenstein | Aaron M. Tenenbaum
 */
public class WArcNode extends ArcNode {

    private String weight;

    public WArcNode() {
        this(null, null);
    }

    public WArcNode(String weight) {
        this(null, weight);
    }

    public WArcNode(GraphNode ptr, String weight) {
        super(ptr);
        this.weight = weight;
    }

    public String getWeight() {
        return weight;
    }

    public void setWeight(String w) {
        weight = w;
    }

    @Override
    public String toString() {
        if (ptr != null) {
            if ("".equals(weight)) {
                return "-------> " + ptr.getInfo().toString();
            } else {
                return "--(" + weight + ")--> " + ptr.getInfo().toString();
            }
        } else {
            return weight + ";";
        }
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof WArcNode)) {
            return false;
        }
        WArcNode tmp = (WArcNode) o;

        return (ptr == tmp.ptr && this.getWeight().equals(tmp.getWeight()));
    }
}
